/**
 * 请求统一管理
 */
import Request from '../common/request';
let api = {}

// 通用管理接口------
// 登录
api.login = data => Request.support.post('/admin/login',data);
// 获取主题色
api.getApplicationInfoByUuid = data => Request.support.post('/registerApi/getApplicationInfoByUuid',data);



// 通用接口  权限管理接口--------------
// 获取菜单列表
api.getBcSysMenuList = data => Request.support.post('/permission/getBcSysMenuList',data);
// 添加菜单列表
api.addBcSysMenu = data => Request.support.post('/permission/addBcSysMenu',data);
// 删除菜单列表
api.deleteBcSysMenu = data => Request.support.post('/permission/deleteBcSysMenu',data);
// 获取菜单信息
api.getBcSysMenuInfo = data => Request.support.post('/permission/getBcSysMenuInfo',data);
// 查询角色列表
api.queryRoleList = data => Request.support.post('/permission/queryRoleList',data);
// 更新菜单信息
api.updateBcSysMenuInfo = data => Request.support.post('/permission/updateBcSysMenuInfo',data);

//通用接口 用户管理接口--------------
// 新增用户
api.addUser = data => Request.support.post('/user/addUser',data);
// 删除用户
api.deleteUser = data => Request.support.post('/user/deleteUser',data);
// 获取用户分页信息
api.getUserPage = data => Request.support.post('/user/getUserPage',data);
// 修改用户
api.updateUser = data => Request.support.post('/user/updateUser',data);
// 获取用户分页信息
api.getMenuList = data => Request.support.post('/user/getMenuList',data);

//通用接口 角色管理接口--------------
// 添加角色
api.addRole = data => Request.support.post('/role/addRole',data);
// 删除角色
api.deleteRole = data => Request.support.post('/role/deleteRole',data);
// 查询角色信息
api.getRoleInfo = data => Request.support.post('/role/getRoleInfo',data);
// 查询角色列表
api.queryRolePage = data => Request.support.post('/role/queryRolePage',data);
// 修改角色
api.updateRole = data => Request.support.post('/role/updateRole',data);
api.roleMenuTreeSelect = data => Request.support.post('/permission/roleMenuTreeSelect',data);
api.getUserList = data => Request.support.post('/role/getUserList',data);


api.saveConfig = data => Request.support.post('/config/saveConfig',data);
api.getConfigList = data => Request.support.post('/config/getConfigList',data);

api.listConfFile = data => Request.support.post('/confFile/listConfFile',data);
api.readeConfFile = data => Request.support.post('/confFile/readeConfFile',data);
api.updateConfFile = data => Request.support.post('/confFile/updateConfFile',data);

api.startNginx = data => Request.support.post('/confFile/startNginx',data);
api.reloadNginx = data => Request.support.post('/confFile/reloadNginx',data);
api.checkNginx = data => Request.support.post('/confFile/checkNginx',data);
api.writeConfFile = data => Request.support.post('/confFile/writeConfFile',data);

api.listConfInfo = data => Request.support.post('/confInfo/listConfInfo',data);
api.updateConfInfo = data => Request.support.post('/confInfo/updateConfInfo',data);
api.listServerInfo = data => Request.support.post('/serverInfo/listServerInfo',data);
api.updateServerInfo = data => Request.support.post('/serverInfo/updateServerInfo',data);

api.listLocationInfo = data => Request.support.post('/serverInfo/listLocationInfo',data);
api.updateLocationInfo = data => Request.support.post('/serverInfo/updateLocationInfo',data);

api.listHttpInfo = data => Request.support.post('/serverInfo/listHttpInfo',data);

api.updateHttpInfo = data => Request.support.post('/serverInfo/updateHttpInfo',data);
api.listUpstreamInfo = data => Request.support.post('/serverInfo/listUpstreamInfo',data);
api.updateUpstreamInfo = data => Request.support.post('/serverInfo/updateUpstreamInfo',data);
api.listUpstreamServerInfo = data => Request.support.post('/serverInfo/listUpstreamServerInfo',data);
api.updateUpstreamServerInfo = data => Request.support.post('/serverInfo/updateUpstreamServerInfo',data);
api.updateUpstreamServerStatus = data => Request.support.post('/serverInfo/updateUpstreamServerStatus',data);

api.readConfInfo = data => Request.support.post('/confInfo/readConfInfo',data);
api.writeConfInfo = data => Request.support.post('/confInfo/writeConfInfo',data);


// 模拟接口
api.getlistApi =  function () {
    const res = {
        records: [
            { id: 1, name: '规则主题', code: 'GZZT', createTime: '2024-8-30',remarks:'测试',type:1},
            { id: 2, name: '变量库类型', code: 'BLLX', createTime: '2024-8-30',remarks:'测试',type:2 },
        ],
        total:2,
    };
    const err = {
        code: -1,
        msg: "调用失败",
    };
    // 模拟一个 Promise-like 对象
    return {
        // 假设在正常情况下调用成功
        then: function (onFulfilled, onRejected) {
            // 如果 onFulfilled 是一个函数，则调用它
            if (typeof onFulfilled === 'function') {
                onFulfilled(res);
            }
            // 返回 this 以支持链式调用
            return this;
        },
        // 处理失败的情况
        catch: function (onRejected) {
            // 如果 onRejected 是一个函数，则调用它
            if (typeof onRejected === 'function') {
                onRejected(err);
            }
            // 返回 this 以支持链式调用
            return this;
        },
        // 不论成功或失败都会调用
        finally: function (callback) {
            if (typeof callback === 'function') {
                // 不管成功还是失败都执行 callback
                callback();
            }
            // 返回 this 以支持链式调用
            return this;
        }
    };


}

export default api
